using System;
using System.Data;
using System.Collections;

namespace APP.QUANLY.Entity
{
    /// <summary>
    /// Summary description for KHOMATHANG.
    /// </summary>
    public class KHOMATHANGList : CollectionBase
    {
		private string _ErrMsg;
        public string ErrMsg { get { return _ErrMsg; } }
    	public KHOMATHANGList()
    	{
	    }

		public void Add(KHOMATHANG entity)
		{
            this.List.Add(entity);
		}

        public void Set(int Pos, KHOMATHANG entity)
        {

            this.List.Insert(Pos, entity);
        }

		public void Add(KHOMATHANGList list)
		{	
			foreach(KHOMATHANG entity in list)
			{
				this.Add(entity);
			}
		}
	
		public new virtual Enumerator GetEnumerator()
		{
		    return new Enumerator(this);
		}
		public virtual KHOMATHANG this[int index]
		{
		    get
			{
				return (KHOMATHANG)this.List[index];
			}
			set
			{
				this.List[index] = value;
			}
		}

		#region Find Object And List Object
		//---PrimaryKey
	public virtual KHOMATHANG Find(Guid MAKHO)
	{
	    foreach (KHOMATHANG obj in this.List)
	    {
		if(obj.MAKHO.ToString().ToUpper().Trim() == MAKHO.ToString().ToUpper().Trim())
		{
		    obj.IsExisting = true;
		    return obj;
		}
	    }
	    return null;
	}

	public virtual KHOMATHANG Find(Int32 MAMATHANG)
	{
	    foreach (KHOMATHANG obj in this.List)
	    {
		if(obj.MAMATHANG.ToString().ToUpper().Trim() == MAMATHANG.ToString().ToUpper().Trim())
		{
		    obj.IsExisting = true;
		    return obj;
		}
	    }
	    return null;
	}

    public virtual int GetIndex(Int32 MAMATHANG)
	{
        KHOMATHANG obj = Find(MAMATHANG);
        if (obj != null)
            return this.List.IndexOf(obj);
	    return -1;
	}

public virtual KHOMATHANGList FindListByMAKHO(Guid MAKHO)
{
	try
	{
		KHOMATHANGList List = new KHOMATHANGList();
		foreach (KHOMATHANG obj in this.List)
		{
		    if(obj.MAKHO.ToString().ToUpper().Trim() == MAKHO.ToString().ToUpper().Trim())
		    {
				List.Add(obj);
		    }
		}
		if (List.Count > 0) return List;
        		else return null;
	}
	catch(Exception ex)
    	{
		_ErrMsg = ex.Message;
        		return null;
    	}
}

public virtual KHOMATHANGList FindListByMAMATHANG(Int32 MAMATHANG)
{
	try
	{
		KHOMATHANGList List = new KHOMATHANGList();
		foreach (KHOMATHANG obj in this.List)
		{
		    if(obj.MAMATHANG.ToString().ToUpper().Trim() == MAMATHANG.ToString().ToUpper().Trim())
		    {
				List.Add(obj);
		    }
		}
		if (List.Count > 0) return List;
        		else return null;
	}
	catch(Exception ex)
    	{
		_ErrMsg = ex.Message;
        		return null;
    	}
}
		//---NonPrimaryKey
        public virtual KHOMATHANG FindBySOLUONGSI(decimal SOLUONGSI)
        {
	        foreach (KHOMATHANG obj in this.List)
	        {
		        if(obj.SOLUONGSI.ToString().ToUpper().Trim() == SOLUONGSI.ToString().ToUpper().Trim())
		        {
		            obj.IsExisting = true;
		            return obj;
		        }
	        }
	        return null;
        }

        public virtual KHOMATHANG FindBySOLUONGLE(decimal SOLUONGLE)
        {
	        foreach (KHOMATHANG obj in this.List)
	        {
		        if(obj.SOLUONGLE.ToString().ToUpper().Trim() == SOLUONGLE.ToString().ToUpper().Trim())
		        {
		            obj.IsExisting = true;
		            return obj;
		        }
	        }
	        return null;
        }

public virtual KHOMATHANGList FindListBySOLUONGSI(decimal SOLUONGSI)
{
	try
	{
		KHOMATHANGList List = new KHOMATHANGList();
		foreach (KHOMATHANG obj in this.List)
		{
			if(obj.SOLUONGSI.ToString().ToUpper().Trim() == SOLUONGSI.ToString().ToUpper().Trim())
			{
				List.Add(obj);
			}
		}
		if (List.Count > 0) return List;
        		else return null;
	}
	catch(Exception ex)
	{
		 _ErrMsg = ex.Message;
       	 	return null;
    	}
}


public virtual KHOMATHANGList FindListBySOLUONGLE(decimal SOLUONGLE)
{
	try
	{
		KHOMATHANGList List = new KHOMATHANGList();
		foreach (KHOMATHANG obj in this.List)
		{
			if(obj.SOLUONGLE.ToString().ToUpper().Trim() == SOLUONGLE.ToString().ToUpper().Trim())
			{
				List.Add(obj);
			}
		}
		if (List.Count > 0) return List;
        		else return null;
	}
	catch(Exception ex)
	{
		 _ErrMsg = ex.Message;
       	 	return null;
    	}
}
		#endregion
     
		#region Inner Classes
		/// <summary>
		/// Type-specific enumeration class, used by LogCollection.GetEnumerator.
		/// </summary>
		public class Enumerator : IEnumerator
		{
			private IEnumerator wrapped;

			public Enumerator(KHOMATHANGList collection)
			{
				this.wrapped = ((CollectionBase)collection).GetEnumerator();
			}

			public KHOMATHANG Current
			{
				get
				{
					return (KHOMATHANG)(this.wrapped.Current);
				}
			}

			object IEnumerator.Current
			{
				get
				{
					return (KHOMATHANG)(this.wrapped.Current);
				}
			}

			public bool MoveNext()
			{
				return this.wrapped.MoveNext();
			}

			public void Reset()
			{
				this.wrapped.Reset();
			}
      }
      #endregion  
   }
}